package moe.oil.dto.user;


import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import moe.oil.config.ConfigConstraint;
import moe.oil.dto.feedback.FeedbackDTO;
import moe.oil.dto.school.CommentsDTO;
import moe.oil.dto.school.SchoolDTO;
import moe.oil.validation.grop.OnInsert;
import moe.oil.validation.grop.OnUpdate;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@Data
@Accessors(chain = true)
@NoArgsConstructor
@Validated({OnUpdate.class})
public class UserDTO {

    @NotNull(message = "TargetId不能为空")

    private Long userId;

    @Valid
    @NotBlank(message = "用户名不能为空", groups = {OnInsert.class, OnUpdate.class})
    @Length(max = ConfigConstraint.MAX_USERNAME_LENGTH,
            min = ConfigConstraint.MIN_USERNAME_LENGTH)
    private String username;

    private SessionDTO sessionDTO;


    @Valid
    @NotBlank(message = "密码不能为空", groups = {OnInsert.class, OnUpdate.class})
    @Length(max = ConfigConstraint.MAX_PASSWORD_LENGTH,
            min = ConfigConstraint.MIN_PASSWORD_LENGTH)
    @NotBlank(message = "密码不能为空")
    private String password;

    @Email(message = "邮箱格式不正确",groups = {OnInsert.class,OnUpdate.class})
    private String email;

    @Valid
    @NotNull(message = "学校不能为空",
            groups = {OnUpdate.class})
    private SchoolDTO schoolDTO = new SchoolDTO();

    //todo 如果为空给默认值
    private UserTargetDTO userTargetDTO = new UserTargetDTO();


    @Valid
    private List<FeedbackDTO> feedBacks = new ArrayList<>(0);

    @Valid
    private List<CommentsDTO> comments = new ArrayList<>(0);

    public UserDTO(String username, String password, String email) {
        this.username = username;
        this.password = password;
        this.email = email;
    }


}
